package com.fight.strive.sys.modules.rbac.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fight.strive.sys.modules.common.PageR;
import com.fight.strive.sys.modules.exception.StriveException;
import com.fight.strive.sys.modules.mybatis.MyBatisPlusUtils;
import com.fight.strive.sys.modules.rbac.dao.RbacPermissionMapper;
import com.fight.strive.sys.modules.rbac.entity.RbacPermissionEntity;
import com.fight.strive.sys.modules.rbac.service.RbacPermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
@Slf4j
public class RbacPermissionServiceImpl
        extends ServiceImpl<RbacPermissionMapper, RbacPermissionEntity>
        implements RbacPermissionService {

    @Override
    public void savePermission(RbacPermissionEntity entity) {
        try {
            this.saveOrUpdate(entity);
        } catch (DuplicateKeyException e) {
            throw new StriveException("功能权限代码重复");
        }
    }

    @Override
    public IPage<RbacPermissionEntity> listByPage(PageR<RbacPermissionEntity> page) {
        QueryWrapper<RbacPermissionEntity> queryWrapper = new QueryWrapper<>();
        MyBatisPlusUtils.buildRuleQuery(queryWrapper, page);
        return this.page(page, queryWrapper);
    }

    @Override
    public List<RbacPermissionEntity> listByRoleIdAndResourceId(Long roleId, Long resourceId) {
        return null;
    }

    @Override
    public Map<String, Boolean> listPermissionCodeByRoleIdAndResourceId(Long roleId, Long resourceId) {
        return null;
    }
}
